#! /bin/sh
#############################################################################
# Licensed Materials - Property of IBM
# 
# Governed under the terms of the International
# License Agreement for Non-Warranted Sample Code.
# 
# (C) COPYRIGHT International Business Machines Corp. 1995 - 2006 
# All Rights Reserved.
#
# US Government Users Restricted Rights - Use, duplication or
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
#############################################################################
# SCRIPT: bldrtn
# Builds Solaris Micro Focus COBOL routines (stored procedures)
# Usage: bldrtn <stored_proc_name> [ <db_name> ]

# Set DB2PATH to where DB2 will be accessed.
# The default is the standard instance path.
DB2PATH=$HOME/sqllib

# Set COBCPY to include the DB2 COPY files directory.
COBCPY=$COBCPY:$DB2PATH/include/cobol_mf
export COBCPY

bitwidth=32
# Uncomment the following line to compile 64-bit applications
#bitwidth=64

if [ $bitwidth = "64" ]; then
  LIB=lib64
  EXTRA_COBOL_FLAG="-C MFSYNC"
else
  LIB=lib32
  EXTRA_COBOL_FLAG=""
fi

# If an embedded SQL program, precompile and bind it.
if [ -f $1".sqb" ]
then
  ./embprep $1 $2
fi

# Compile the program.
cob $EXTRA_COBOL_FLAG -cx $1.cbl

# Link the program.
cob -yo $1 $1.o -L$DB2PATH/$LIB -ldb2 -ldb2gmf

# Copy the shared library to the sqllib/function subdirectory.
# The user must have write permission to this directory.
rm -f $DB2PATH/function/$1
cp $1 $DB2PATH/function
